package com.yunfangdata.service.impl;

import com.yunfangdata.domain.Classroom;
import com.yunfangdata.mapper.ClassroomMapper;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.IClassroomService;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassroomServiceImpl implements IClassroomService {


    @Autowired
    private ClassroomMapper mapper;


    public void save(Classroom entity) {
        mapper.insert(entity);
    }


    public void update(Classroom entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public List<Classroom> list() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        //1:查总条数
        int total = mapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        //2:查分页数据
        List<Classroom> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }

    public void changeState(Long id) {
        mapper.changeState(id);
    }
}

